<?php 
defined('IN_YYS')or exit('Access Denied.');
System::DOWN_App_class('base','member','no');
System::DOWN_App_fun('my','index');
System::DOWN_App_fun('user','index');
System::DOWN_sys_fun('user');

class mobile extends base {

	public function __construct(){
		parent::__construct();
		$this->db=System::DOWN_sys_class('model');
		
		if(!$this->userinfo && $_SERVER['REQUEST_URI'] != '/mobile/mobile/guanzhu/'){
			//wechat_login();
		}
		//邀请关系
        session_start();
        if(isset($_GET['yaoqing']) && $_GET['yaoqing'] != null){
            $_SESSION['uu'] = $_GET['yaoqing'];
        }
        if(isset($_GET['fid']) && $_GET['fid'] != null){
            $_SESSION['fid'] = $_GET['fid'];
            $_SESSION['uu'] = $_GET['fid'];
        }
		
		/*$wxInfo = $this->db->YOne("select * from `@#_wxset`");
		
		$this->appId = 'wx5d39297978df0723';//$wxInfo['appid'];
		$this->appSecret = '738e846fa794da2a69cd403eba5bb4b1';//$wxInfo['secret'];
		$this->nav = $this->segment(2);*/
	}	

	//首页
	public function init(){

		//邀请关系
        session_start();
		if(isset($_GET['yaoqing']) && $_GET['yaoqing'] != null){
			$_SESSION['uu'] = $_GET['yaoqing'];
		}
        if(isset($_GET['fid']) && $_GET['fid'] != null){
            $_SESSION['fid'] = $_GET['fid'];
            $_SESSION['uu'] = $_GET['fid'];
        }

		$webname=$this->_yys['web_name'];
		$biaoti=""._yys("web_name");
		$index="i0";
		
		//佣金部分开始
		$deng=$this->userinfo;
		if($_GET['yaoqing']){
			$uu=$_GET['yaoqing'];
			session_start();
			$_SESSION['uu']=$uu;
		}

		if($_GET['yaoqing2']){
			$yaoqing2=$_GET['yaoqing2'];
			session_start();
			$_SESSION['yaoqing2']=$yaoqing2;
		}

		if($_GET['yaoqing3']){
			$yaoqing3=$_GET['yaoqing3'];
			session_start();
			$_SESSION['yaoqing3']=$yaoqing3;
		}
		//var_dump($_SESSION['yaoqing2']);
		require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
      
	   $appid = $yaoqing[appid];
	   $secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		//exit;
		

		
		//最新商品
		$new_shop=$this->db->YOne("select * from `@#_zg_shangpin` where `pos` = '1' and `q_end_time` is null ORDER BY `id` DESC LIMIT 1");

		//即将揭晓
		$yyslist = $this->db->Ylist("select * from `@#_zg_shangpin` where `q_end_time` is null ORDER BY `shenyurenshu` ASC LIMIT 8");

		//人气商品
		$yyslistrenqi=$this->db->Ylist("select * from `@#_zg_shangpin` where `renqi`='1' and `q_end_time` is null ORDER BY id DESC LIMIT 12");
		
		//直购人气商品
		$yyslistrenqizg=$this->db->Ylist("select * from `@#_zg_shangpin` where `renqi`='1' and `q_end_time` is null ORDER BY id DESC LIMIT 8");

		//最新揭晓
		$yysqishu=$this->db->Ylist("select * from `@#_zg_shangpin` where `q_end_time` is not null and `q_showtime` = 'N' ORDER BY `q_end_time` DESC LIMIT 4");
		
		$jinri_shoplist = $this->db->Ylist("select * from `@#_zg_shangpin` where `xsjx_time` > '$w_jinri_time' and `xsjx_time` < '$w_minri_time' order by xsjx_time limit 0,3 ");

		$shouji_tu = $this->db->YList("select * from `@#_shouji` order by id desc limit 4");
		/*require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
		$appid = $yaoqing[appid];
		$secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		$biaoti = "首页";*/
	
		/*公告列表*/		      	


		/*
		*	导航图
		*	这里放大类
		*/
		$nav_list = $this->db->YList("select * from `@#_daohang` where `type` = 'mobile' and `status` = 'Y' order by `order` desc");
		foreach($nav_list as $key => $one){
			if($one['thumb']){
				$nav_list[$key]['thumb'] = $one['thumb'];
			}else{
				$nav_list[$key]['thumb'] = 'pp.gif';
			}
		}
		
		/*品牌图*/
		$brand_list = $this->db->YList("select * from `@#_fenlei` where `model` = '1' order by `order` desc,`cateid` desc limit 10");
	

		foreach($brand_list as $key => $one){
			$info = unserialize($one['info']);
			if($info['thumb']){
				$brand_list[$key]['thumb'] = $info['thumb'];
			}else{
				$brand_list[$key]['thumb'] = 'pp.gif';
			}
		}
		
		$brand_list_two = $this->db->YList("select * from `@#_fenlei` where `model` = '1' order by `order` desc,`cateid` desc");
	
		$action = 'index';
		/*首页广告调用*/
		$gg1=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '1'");
		$gg2=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '2'");
		$gg3=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '3'");
		$gg4=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '4'");
		$gg5=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '5'");
		$gg6=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '6'");
		
		$gg7=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '7'");
		$gg8=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '8'");
		$gg9=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '9'");
		$gg10=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '10'");
		$gg11=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '11'");
		$gg12=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '12'");
		
		/*如果没有正在开奖，则取最近开奖的四个*/
		$prizeList = $this->db->Ylist("select * from `@#_shangpin` where `canyurenshu` = `zongrenshu` and `shenyurenshu` = '0' and `q_showtime` = 'N' and `q_uid` IS NOT NULL order by `q_end_time` desc,`id` desc limit 4"); 
		if($prizeList){
			foreach($prizeList as $key => $one){
				$username = unserialize($one['q_user']);
				$prizeList[$key]['username'] = $username['username'];
			}
		}
		if( !$_GET['yaoqing'] && !$_GET['fid']) {
			include templates("mobile/index","index");
		}else{
			header("location:/mobile/user/login");
		}
	}	
	

	//商品列表
	public function glist(){
        $webname=$this->_yys['web_name'];	
		$biaoti="所有商品";
		$index="i1";
		$cateid = intval($this->segment(4));
		/*品牌图*/
		$brand_list = $this->db->YList("select * from `@#_fenlei` where `model` = '1' order by `order` desc,`cateid` desc limit 10");
	
		foreach($brand_list as $key => $one){
			$info = unserialize($one['info']);
			if($info['thumb']){
				$brand_list[$key]['thumb'] = $info['thumb'];
			}else{
				$brand_list[$key]['thumb'] = 'pp.gif';
			}
		}

		/*所有分类*/
		$fenlei_list = $this->db->Ylist("select * from `@#_fenlei` where `model` = '1' and `parentid` = '0' order by `order` DESC");	
		
		/*地理位置信息*/
		$huiyuan=$this->userinfo;
		$locationId=$huiyuan['locationId'];
		$location = $this->db->YOne("select * from `@#_yonghu_location` where `id`='$locationId'");
		$districtCode = $location['xian'];
		$district = $this->db->YOne("select * from `@#_area` where `code`='$districtCode'");
		$action = 'glist';
		include templates("mobile/index","glist");
	}
	
	
	public function glistsearch(){
		$skey = $_POST['skey'];
        $webname=$this->_yys['web_name'];	
		$biaoti="商品列表_"._yys("web_name");
		$key="所有商品";
		include templates("mobile/index","glistsearch");
	}
	public function glistsearchzg(){
		$skey = $_POST['skey'];
        $webname=$this->_yys['web_name'];	
		$biaoti="商品列表_"._yys("web_name");
		$key="所有商品";
		include templates("mobile/index","glistsearchzg");
	}

	//参与规则
	public function guize(){
        $webname=$this->_yys['web_name'];	
		$biaoti="参与规则_"._yys("web_name");
		$key="参与规则";
		include templates("mobile/index","guize");
	}	
	
	//引导关注公众号
	public function guanzhu(){
        $webname=$this->_yys['web_name'];	
		$biaoti="关注公众号_"._yys("web_name");
		//二维码在后台广告模块上传
		$guanggao13=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '13'");
		$guanggao14=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '14'");
		include templates("mobile/index","guanzhu");
	}	
	
	//新增反馈公告三个页面
	public function problem(){
		$fenlei = $this->db->YOne("select * from `@#_fenlei` where `parentid`='2' and `name`='常见问题'");
		$wenzhang = $this->db->Ylist("select * from `@#_wenzhang` where `cateid`='$fenlei[cateid]'");
		$webname = $this->_yys['web_name'];	
		$biaoti = "商品列表_"._yys("web_name");
		$key = "常见问题";
		$header = '点击查看常见问题，反馈意见给我们';
		include templates("mobile/index","problem");
	}
	
	
	public function gonggao(){
		$fenlei=$this->db->YOne("select * from `@#_fenlei` where `parentid`='1' and `name`='最新动态'");
		$wenzhang=$this->db->Ylist("select * from `@#_wenzhang` where `cateid`='$fenlei[cateid]'");
		$webname=$this->_yys['web_name'];	
		$biaoti="公告动态_"._yys("web_name");
		$key="最新动态";
		include templates("mobile/index","gonggao");
	}
	public function Suggestion(){
		$skey = $_POST['skey'];
        $webname=$this->_yys['web_name'];	
		$biaoti="商品列表_"._yys("web_name");
		$key="意见反馈";
		include templates("mobile/index","Suggestion");
	}
	public function SuggestionData(){
		
		$Content = $_REQUEST['content'];
		$Info = $_REQUEST['info'];
		$zt = $_REQUEST['zt'];
		
		$sql = "INSERT INTO `@#_suggestion` (`Content`,`Info`,`zt`) VALUES ('$Content','$Info','$zt')";
		$res = $this->db->Query($sql);
		if($res){
			$result['code'] = 0;
		}else{
			$result['code'] = 1;
		}
		echo json_encode($result);
	}
	public function ProblemDetails(){
		$wenzhangid = safe_replace($this->segment(4));
		$wenzhang=$this->db->YOne("SELECT * FROM `@#_wenzhang` where `id` = '$wenzhangid' LIMIT 1");
		if($wenzhang){
			$cateinfo = $this->db->YOne("SELECT * FROM `@#_fenlei` where `cateid` = '$wenzhang[cateid]' LIMIT 1");
		}else{
			$cateinfo = array("info"=>null);
		}		
		$info=unserialize($cateinfo['info']);

		$skey = $_POST['skey'];
        $webname=$this->_yys['web_name'];	
		$biaoti="商品列表_"._yys("web_name");
		$key="意见反馈";
		$header = $wenzhang['title'];
		include templates("mobile/index","ProblemDetails");
	}
	
	//新增自助众筹与供应商发布说明专用页
	public function friend(){
		$wenzhangid = safe_replace($this->segment(4));
		$wenzhang=$this->db->YOne("SELECT * FROM `@#_wenzhang` where `id` = '$wenzhangid' LIMIT 1");
		if($wenzhang){
			$cateinfo = $this->db->YOne("SELECT * FROM `@#_fenlei` where `cateid` = '$wenzhang[cateid]' LIMIT 1");
		}else{
			$cateinfo = array("info"=>null);
		}		
		$info=unserialize($cateinfo['info']);

		$skey = $_POST['skey'];
        $webname=$this->_yys['web_name'];	
		$biaoti="人脉总动员，开心玩出钱"._yys("web_name");
		$key="人脉总动员，开心玩出钱";
		include templates("mobile/index","friend");
	}
	public function zzfb(){
		$wenzhangid = safe_replace($this->segment(4));
		$wenzhang=$this->db->YOne("SELECT * FROM `@#_wenzhang` where `id` = '$wenzhangid' LIMIT 1");
		if($wenzhang){
			$cateinfo = $this->db->YOne("SELECT * FROM `@#_fenlei` where `cateid` = '$wenzhang[cateid]' LIMIT 1");
		}else{
			$cateinfo = array("info"=>null);
		}		
		$info=unserialize($cateinfo['info']);

		$skey = $_POST['skey'];
        $webname=$this->_yys['web_name'];	
		$biaoti="如何成为供应商及发布项目"._yys("web_name");
		$key="如何成为供应商及发布项目";
		include templates("mobile/index","zzfb");
	}
	//新手关注送红包二维码扫码页面
	public function hongbao(){
	 $webname=$this->_yys['web_name'];

	include templates("mobile/index","hongbao");
	}		
	
	//ajax获取商品列表信息
	public function glistajax(){
	    $webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($this->segment(4));
		$select =htmlspecialchars($this->segment(5));		
		$p =htmlspecialchars($this->segment(6)) ? $this->segment(6) :1;		
		

		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_fenlei` where `parentid` = '$cate_band'");
				foreach($sun_cate as $v){
					$sun_id_str .= "'".$v['cateid']."'".",";
				}		
				$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if(!$select){
			$select = '10';
		}		
		if($cate_band){
			$fen1 = intval($cate_band);	
			$cate_band = 'list';			
		}
		if(empty($fen1)){
			$pinpai=$this->db->Ylist("select * from `@#_pinpai` where 1 order by `order` DESC");	
			$daohangs = '所有分类';	
		}else{
			$pinpai=$this->db->Ylist("select * from `@#_pinpai` where `cateid`='$fen1' order by `order` DESC");
			$daohangs=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
			$daohangs = $daohangs['name'];			
		}	
			
		$fenlei=$this->db->Ylist("select * from `@#_fenlei` where `model` = '1'");
		

		//

		
		//分页
		
		$end=10;
		$star=($p-1)*$end;
		
		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `time` DESC';
		}
		if($select == 50){
			$select_w = 'order by `money` DESC';
		}
		if($select == 55){
			$select_w = 'order by `money` ASC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

				 
		if($fen1){		
			$count=$this->db->Ylist("select * from `@#_shangpin` where `q_uid` is null and `cateid` in ($newstr) $select_w");
		}else{			
			$count=$this->db->Ylist("select * from `@#_shangpin` where `q_uid` is null $select_w");
		}
		if($fen1){
			
			$yyslist=$this->db->Ylist("select * from `@#_shangpin` where `q_uid` is null and `cateid` in ($newstr) $select_w limit $star,$end");
		}else{			
			$yyslist=$this->db->Ylist("select * from `@#_shangpin` where `q_uid` is null $select_w limit $star,$end");
		} 
		$max_renqi_qishu = 1;
		$max_renqi_qishu_id = 1;

		if(!empty($yyslistrenqi)){
			foreach ($yyslistrenqi as $renqikey =>$renqiinfo){
				if($renqiinfo['qishu'] >= $max_renqi_qishu){			
					$max_renqi_qishu = $renqiinfo['qishu'];
					$max_renqi_qishu_id = $renqikey;				
				}		
			}	
			$yyslistrenqi[$max_renqi_qishu_id]['t_max_qishu'] = 1;	
		}	
		
		
		$this_time = time();
		if(count($yyslist) > 1){
					if($yyslist[0]['time'] > $this_time - 86400*3)
					$yyslist[0]['t_new_goods'] = 1;
		}
		$fenyex=ceil(count($count)/$end);
		if($p<=$fenyex){
			$yyslist[0]['page']=$p+1;
		}
		if($fenyex>0){
			$yyslist[0]['sum']=$fenyex;
		}else if($fenyex==0){
			$yyslist[0]['sum']=$fenyex;
		}
		
		echo json_encode($yyslist);
	}
	//所有商品分类列表结束，专属商品开始

	//商品详细
	public function item(){
		//佣金部分开始
		$deng=$this->userinfo;
		if($_GET['yaoqing']){
			$uu=$_GET['yaoqing'];
			session_start();
			$_SESSION['uu']=$uu;
		}

		if($_GET['yaoqing2']){
			$yaoqing2=$_GET['yaoqing2'];
			session_start();
			$_SESSION['yaoqing2']=$yaoqing2;
		}

		if($_GET['yaoqing3']){
			$yaoqing3=$_GET['yaoqing3'];
			session_start();
			$_SESSION['yaoqing3']=$yaoqing3;
		}
		//var_dump($_SESSION['yaoqing2']);
		require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
      
	   $appid = $yaoqing[appid];
	   $secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		//exit;
		
		$id = intval($this->segment(4));
		$shopInfo = $this->db->Yone("select * from `@#_shangpin` where `id` = '$id'");
		$picarr = unserialize($shopInfo['picarr']);
		if($shopInfo['supplierId']){
			$supplierName = getSupplierInfo($shopInfo['supplierId'],'name');
		}
		$shopList = $this->db->YList("select * from `@#_shangpin` where `sid` = '$shopInfo[sid]' order by id DESC");
		$q_showtime = (isset($shopInfo['q_showtime']) && $shopInfo['q_showtime'] == 'N') ? 'N' : 'Y';
		if($shopInfo['q_end_time'] && $q_showtime == 'N'){
			header("location: ".LOCAL_PATH."/mobile/mobile/dataserver/".$shopInfo['id']);
			exit;			
		}
		$biaoti=$shopInfo['title'];
		//佣金部分结束
		$key="商品详情";
		$mysql_model = System::DOWN_sys_class('model');
		$xiangmuid = safe_replace($this->segment(4));	
		$xiangmu = $mysql_model->YOne("select * from `@#_shangpin` where `id`='".$xiangmuid."' LIMIT 1");
		$xiangmu['width'] = ($xiangmu['canyurenshu'] / $xiangmu['zongrenshu'])*100;
		$xiangouss = System::DOWN_App_config("user_fufen");

		if(!empty($xiangmu[id])&&$this->userinfo){
			$huiyuan=$this->userinfo;
			$counts1=$this->db->Ylist("select gonumber  from `@#_yonghu_yys_record` where `uid`=$huiyuan[uid] and `shopid`=$xiangmu[id]");
			for($xs=0;$xs < $xiangouss[xiangou];$xs++){	
				$sums +=$counts1[$xs][gonumber];
			}
			$counts=intval($sums);
		}
		
		//限购结束
		if(!$xiangmu)_notemobile("商品不存在！");
		$q_showtime = (isset($xiangmu['q_showtime']) && $xiangmu['q_showtime'] == 'N') ? 'N' : 'Y';
		if($xiangmu['q_end_time'] && $q_showtime == 'N'){
			header("location: ".LOCAL_PATH."/mobile/mobile/dataserver/".$xiangmu['id']);
			exit;			
		}
		$sid=$xiangmu['sid'];
		$sid_code=$mysql_model->YOne("select * from `@#_shangpin` where `sid`='$sid' order by `id` DESC LIMIT 1,1");
		$sid_go_record=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `shopid`='$sid_code[sid]' and `uid`='$sid_code[q_uid]' order by `id` DESC LIMIT 1");
		
		
		$fenlei=$mysql_model->YOne("select * from `@#_fenlei` where `cateid` = '$xiangmu[cateid]' LIMIT 1");
		$pinpai=$mysql_model->YOne("select * from `@#_pinpai` where `id`='$xiangmu[brandid]' LIMIT 1");
		
		$biaoti=$xiangmu['title'];
		$nomal=$xiangmu['zongrenshu']-$xiangmu['canyurenshu'];
		$xiangmu['picarr'] = unserialize($xiangmu['picarr']) ;
	
		$we=$mysql_model->Ylist("select * from `@#_yonghu_yys_record` where `shopid`='".$xiangmuid."' AND `shopqishu`='".$xiangmu['qishu']."'ORDER BY id DESC LIMIT 6");
		$xiangmulist = $this->db->Ylist("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `q_end_time` is not null order by `qishu` DESC");
		$xiangmuzx=$this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");
		$wangqiqishu='';
		if (empty($xiangmu['q_end_time']) && empty($xiangmu['q_uid'])){
			$wangqiqishu.='<li class="cur"><a href="'.LOCAL_PATH.'/mobile/mobile/item/'.$xiangmu['id'].'">'."第".$xiangmu['qishu']."期</a><b></b></li>";
		}else{
			$wangqiqishu.='<li class="cur"><a href="'.LOCAL_PATH.'/mobile/mobile/item/'.$xiangmuzx['id'].'">'."第".$xiangmuzx['qishu']."期</a><b></b></li>";
		}
		if(empty($xiangmulist)){
		foreach($xiangmulist as $qitem){			
			$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/item/'.$qitem['id'].'" class="">第'.$qitem['qishu'].'期</a></li>';		
			
		}}
		
		foreach($xiangmulist as $qitem){
			if($qitem['id'] == $xiangmuid){
				$wangqiqishu.='<li class="cur"><a href="javascript:;">'."第".$xiangmulist[0]['qishu']."期</a><b></b></li>";
			}else{				
				$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/dataserver/'.$qitem['id'].'" >第'.$qitem['qishu'].'期</a></li>';		
			}
		}
		$gorecode=array();
		if(!empty($xiangmulist)){ 
			//查询上期的获奖者信息
			$gorecode=$this->db->YOne("select * from `@#_yonghu_yys_record` where `shopid`='".$xiangmulist[0]['id']."' AND `shopqishu`='".$xiangmulist[0]['qishu']."' ORDER BY id DESC LIMIT 1");
		}

		 $curtime=time();
         $shopitem='itemfun';
		 

		
		include templates("mobile/index","item");
	}
	
	
	
	
	//ajax获取直购商品列表信息开始
	public function glistajaxzg(){
	    $webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($this->segment(4));
		$select =htmlspecialchars($this->segment(5));		
		$p =htmlspecialchars($this->segment(6)) ? $this->segment(6) :1;		
		

		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_zg_fenlei` where `parentid` = '$cate_band'");
				foreach($sun_cate as $v){
					$sun_id_str .= "'".$v['cateid']."'".",";
				}		
				$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if(!$select){
			$select = '10';
		}		
		if($cate_band){
			$fen1 = intval($cate_band);	
			$cate_band = 'list';			
		}
		if(empty($fen1)){
			$pinpai=$this->db->Ylist("select * from `@#_zg_pinpai` where 1 order by `order` DESC");	
			$daohangs = '所有分类';	
		}else{
			$pinpai=$this->db->Ylist("select * from `@#_zg_pinpai` where `cateid`='$fen1' order by `order` DESC");
			$daohangs=$this->db->YOne("select * from `@#_zg_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
			$daohangs = $daohangs['name'];			
		}	
			
		$fenlei=$this->db->Ylist("select * from `@#_zg_fenlei` where `model` = '1'");
		

		//

		
		//分页
		
		$end=10;
		$star=($p-1)*$end;
		
		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `time` DESC';
		}
		if($select == 50){
			$select_w = 'order by `money` DESC';
		}
		if($select == 55){
			$select_w = 'order by `money` ASC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

				 
		if($fen1){		
			$count=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and `q_uid` is null and `cateid` in ($newstr) $select_w");
		}else{			
			$count=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and `q_uid` is null $select_w");
		}
		if($fen1){
			
			$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and `q_uid` is null and `cateid` in ($newstr) $select_w limit $star,$end");
		}else{			
			$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and `q_uid` is null $select_w limit $star,$end");
		} 
		$max_renqi_qishu = 1;
		$max_renqi_qishu_id = 1;

		if(!empty($yyslistrenqi)){
			foreach ($yyslistrenqi as $renqikey =>$renqiinfo){
				if($renqiinfo['qishu'] >= $max_renqi_qishu){			
					$max_renqi_qishu = $renqiinfo['qishu'];
					$max_renqi_qishu_id = $renqikey;				
				}		
			}	
			$yyslistrenqi[$max_renqi_qishu_id]['t_max_qishu'] = 1;	
		}	
		
		
		$this_time = time();
		if(count($yyslist) > 1){
					if($yyslist[0]['time'] > $this_time - 86400*3)
					$yyslist[0]['t_new_goods'] = 1;
		}
		$fenyex=ceil(count($count)/$end);
		if($p<=$fenyex){
			$yyslist[0]['page']=$p+1;
		}
		if($fenyex>0){
			$yyslist[0]['sum']=$fenyex;
		}else if($fenyex==0){
			$yyslist[0]['sum']=$fenyex;
		}
		
		echo json_encode($yyslist);
	}
	//商品详细
	public function goods(){
		//佣金部分开始
		/*邀请佣金 微信分享部分*/
		//邀请关系
        session_start();
		if(isset($_GET['yaoqing']) && $_GET['yaoqing'] != null){
			$_SESSION['uu'] = $_GET['yaoqing'];
		}
        if(isset($_GET['fid']) && $_GET['fid'] != null){
            $_SESSION['fid'] = $_GET['fid'];
            $_SESSION['uu'] = $_GET['fid'];
        }

		$webname=$this->_yys['web_name'];
		$biaoti=""._yys("web_name");
		$index="i0";
		
		//佣金部分开始
		$deng=$this->userinfo;
		if($_GET['yaoqing']){
			$uu=$_GET['yaoqing'];
			session_start();
			$_SESSION['uu']=$uu;
		}

		if($_GET['yaoqing2']){
			$yaoqing2=$_GET['yaoqing2'];
			session_start();
			$_SESSION['yaoqing2']=$yaoqing2;
		}

		if($_GET['yaoqing3']){
			$yaoqing3=$_GET['yaoqing3'];
			session_start();
			$_SESSION['yaoqing3']=$yaoqing3;
		}
		//var_dump($_SESSION['yaoqing2']);
		require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
      
	   $appid = $yaoqing[appid];
	   $secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		//exit;
		
		/*佣金部分结束*/
		
		$index="i1";
	    $webname=$this->_yys['web_name'];
		$key="商品详情";
		$mysql_model=System::DOWN_sys_class('model');
		$xiangmuid=safe_replace($this->segment(4));	
		
		$xiangmu=$mysql_model->YOne("select * from `@#_zg_shangpin` where `id`='".$xiangmuid."' LIMIT 1");
		//限购
		$xiangouss = System::DOWN_App_config("user_fufen");
		//图文详情插入
		$xiangmuid=intval($this->segment(4));
		$desc=$this->db->YOne("select * from `@#_zg_shangpin` where `id`='$xiangmuid'");
		
		if(!empty($xiangmu[id])&&$this->userinfo){
			$huiyuan=$this->userinfo;
			
			$counts1=$this->db->Ylist("select gonumber  from `@#_zg_yonghu_yys_record` where `uid`=$huiyuan[uid] and `shopid`=$xiangmu[id]");
			
			
			for($xs=0;$xs < $xiangouss[xiangou];$xs++){	
				$sums +=$counts1[$xs][gonumber];
			}
			
			$counts=intval($sums);

		}
		//限购结束
		if(!$xiangmu)_notemobile("商品不存在！");
		
		$hitplus=$mysql_model->Query("update `@#_zg_shangpin` set `hit` = `hit` + 1 where `id`='".$xiangmuid."'");
		$xiangmu['hit']++;
		
		$q_showtime = (isset($xiangmu['q_showtime']) && $xiangmu['q_showtime'] == 'N') ? 'N' : 'Y';
		if($xiangmu['q_end_time'] && $q_showtime == 'N'){
			header("location: ".LOCAL_PATH."/mobile/mobile/goods/".$xiangmu['id']);
			exit;			
		}
		$sid=$xiangmu['sid'];
		$sid_code=$mysql_model->YOne("select * from `@#_zg_shangpin` where `sid`='$sid' order by `id` DESC LIMIT 1,1");
		$sid_go_record=$mysql_model->YOne("select * from `@#_zg_yonghu_yys_record` where `shopid`='$sid_code[sid]' and `uid`='$sid_code[q_uid]' order by `id` DESC LIMIT 1");
		
		
		$fenlei=$mysql_model->YOne("select * from `@#_zg_fenlei` where `cateid` = '$xiangmu[cateid]' LIMIT 1");
		$pinpai=$mysql_model->YOne("select * from `@#_zg_pinpai` where `id`='$xiangmu[brandid]' LIMIT 1");
		
		$biaoti=$xiangmu['title'];
		$nomal=$xiangmu['zongrenshu']-$xiangmu['canyurenshu'];
		$xiangmu['picarr'] = unserialize($xiangmu['picarr']) ;
		
		
		$we=$mysql_model->Ylist("select * from `@#_zg_yonghu_yys_record` where `shopid`='".$xiangmuid."' AND `shopqishu`='".$xiangmu['qishu']."'ORDER BY id DESC LIMIT 6");
		
		//$we2=$mysql_model->Ylist("select * from `@#_zg_yonghu_yys_record` where `shopid`='".$xiangmuid."' AND `shopqishu`='".$xiangmu['qishu']."'ORDER BY id DESC");
		
		$xiangmulist = $this->db->Ylist("select * from `@#_zg_shangpin` where `sid`='$xiangmu[sid]' and `q_end_time` is not null order by `qishu` DESC");
		
		$shopList = $this->db->YOne("select * from `@#_shangpin` where `supplierId` = '$xiangmu[supplierId]' order by id DESC");
		$nowShop = $shopList['id'];
		
		//期数显示
		$xiangmuzx=$this->db->YOne("select * from `@#_zg_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");
		//var_dump($xiangmuzx['qishu']);
		$wangqiqishu='';
		//var_dump(empty($xiangmu['q_uid']));
		if (empty($xiangmu['q_end_time']) && empty($xiangmu['q_uid'])){
			$wangqiqishu.='<li class="cur"><a href="'.LOCAL_PATH.'/mobile/mobile/goods/'.$xiangmu['id'].'">'."第".$xiangmu['qishu']."期</a><b></b></li>";
		}else{
			$wangqiqishu.='<li class="cur"><a href="'.LOCAL_PATH.'/mobile/mobile/goods/'.$xiangmuzx['id'].'">'."第".$xiangmuzx['qishu']."期</a><b></b></li>";
		}
		if(empty($xiangmulist)){
		foreach($xiangmulist as $qitem){			
			$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/goods/'.$qitem['id'].'" class="">第'.$qitem['qishu'].'期</a></li>';		
			
		}}
		
		foreach($xiangmulist as $qitem){
			if($qitem['id'] == $xiangmuid){
				
				$wangqiqishu.='<li class="cur"><a href="javascript:;">'."第".$xiangmulist[0]['qishu']."期</a><b></b></li>";
			}else{				
				$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/goods/'.$qitem['id'].'" >第'.$qitem['qishu'].'期</a></li>';		
			}
		}
		$gorecode=array();
		if(!empty($xiangmulist)){ 
		//查询上期的获奖者信息
		$gorecode=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where `shopid`='".$xiangmulist[0]['id']."' AND `shopqishu`='".$xiangmulist[0]['qishu']."' ORDER BY id DESC LIMIT 1");


		}
		//echo "<pre>";
		//print_r($xiangmulist);
		//echo microt($xiangmulist[0]['q_end_time']);exit;
		 $curtime=time();
         $shopitem='itemfun';
		 
		//晒单数
		$shopid=$this->db->YOne("select * from `@#_zg_shangpin` where `id`='$xiangmuid'");
		$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `sid`='$shopid[sid]'");
		$shop='';
		foreach($yyslist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidingdan=$this->db->Ylist("select * from `@#_shai` where `sd_shopid` IN ($id)");
			$sum=0;
			foreach($shaidingdan as $sd){
				$shaidingdan_hueifu=$this->db->Ylist("select * from `@#_shai_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidingdan_hueifu);
			}
		}else{
			$shaidingdan=0;
			$sum=0;
		}
		$xiangmu['expressFee'] = sprintf("%.2f", $xiangmu['expressFee']);
		//获取信誉等级
		$shangjiaid = $xiangmu['supplierId'];
		$shangjia = $this->db->YOne("select * from `@#_supplier` where `id` = '$shangjiaid'");
		$huiyuandjs=$this->db->Ylist("select * from `@#_yonghu_group` where `type` = '商户等级'");
		$jingyan = $shangjia['credibility'];
	    if(!empty($huiyuandjs)){
			foreach($huiyuandjs as $hk=>$hv){
				if($jingyan>=$hv['jingyan_start'] && $jingyan<=$hv['jingyan_end']){
					$xiangmu['level'] = $hv['name'];
					$xiangmu['icon'] = $hv['icon'];
				}
			}
	  	}
		//end获取信誉等级
		if($xiangmu['newTypes']){
			$newType = unserialize($xiangmu['newTypes']);
			
			$newTypeCount = count($newType);
			// echo "<pre>";
			// print_r($newType);
			// die();

			$html = '';
			foreach($newType as $key => $one){
				if($one['type'] == 'select' || $one['type'] == 'radio'){
					
					$html .= '<div id="choose" class="clearfix p-choose-wrap">';
					$html .= '<div id="choose-baitiao" class="li p-choose choose-baitiao hide" style="display: block;">';
					$html .= '<div class="dt">'.$one['name'].'：</div>';

					$html .= '<div class="dd sinwlRadio">';
					foreach($one['sub'] as $tkey => $tone){
						$html .= '<div class="item" ids="'.$one['ids'].'" name="'.$one['name'].'" price="'.$tone['price'].'">';
						$html .= '<b></b>';
						$html .= '<a href="#none">';
						$html .=	'<strong>'.$tone['subname'].'</strong>';
						$html .= '</a>';
						$html .= '</div>';
					}
					$html .= '</div></div></div>';
				}else{
					$html .= '<div id="choose" class="clearfix p-choose-wrap">';
					$html .= '<div id="choose-baitiao" class="li p-choose choose-baitiao hide" style="display: block;">';
					$html .= '<div class="dt">'.$one['name'].'：</div>';

					$html .= '<div class="dd sinwlCheckbox">';
					foreach($one['sub'] as $tkey => $tone){
						$html .= '<div class="item" ids="'.$one['ids'].'" name="'.$one['name'].'" price="'.$tone['price'].'">';
						$html .= '<b></b>';
						$html .= '<a href="#none">';
						$html .=	'<strong>'.$tone['subname'].'</strong>';
						$html .= '</a>';
						$html .= '</div>';
					}
					$html .= '</div></div></div>';
				}
			}
			
			//区分当前的商品
			$uniqid = uniqid();

			/*		$html .= '<tr id="newType_'.$one['ids'].'">';
					$html .= '<td align="right" style="width:120px"><font color="red">*</font>'.$one['name'].'：</td><td>';

					foreach($one['sub'] as $tkey => $tone){
						$html .= '<label class="sinwlLabel"><input type="radio" name="'.$one['name'].'" price="'.$tone['price'].'" value="'.$one.'_'.$tone.'"/>'.$tone['subname'].'</label>';
					}
					$html .= '</td></tr>';
				}else{
					
				}
			}*/
		
		
			/*
				<div id="choose" class="clearfix p-choose-wrap">
					<div id="choose-baitiao" class="li p-choose choose-baitiao hide" style="display: block;">
						<div class="dt">{wc:$newTypeInfo['title']}：</div>
						<div class="dd {wc:if $type == 'radio'}sinwlRadio{wc:elseif $type == 'checkbox'}sinwlCheckbox{wc:elseif $type == 'select'}sinwlSelect{wc:elseif $type == 'input'}sinwlInput{wc:if:end}">
							{wc:loop $typePart $sub}
								<div class="item">
									<b></b>
									<a href="#none">
										<strong> {wc:$sub}</strong>
									</a>
								</div>
							{wc:loop:end}
						</div>
					</div>
				</div>
			
			*/
		
			/*
			foreach($newType as $key => $one){
				$newTypeInfo = $this->db->YOne("select * from `@#_zg_types` where `id` = '$one'");

				$type = $newTypeInfo['type'];
				$typePart = explode(',',$newTypeInfo['content']);

				if($type == 'text'){
					$html  = '<tr id="newType_'.$one.'"><td align="right" style="width:120px"><font color="red">*</font>'.$newTypeInfo['title'].'：</td><td>';
					$html .= '<input type="text" />';
					$html .= '</tr>';
				}elseif($type == 'select'){
					$html  = '<tr id="newType_'.$one.'"><td align="right" style="width:120px"><font color="red">*</font>'.$newTypeInfo['title'].'：</td><td>';
					$html .= '<select name="newType">';
					foreach($typePart as $tkey => $tone){
						$html .= '<option value="'.$one.'_'.$tone.'">'.$tone.'</option>';
					}
					$html .= '</select></td></tr>';
				}elseif($type == 'radio'){
					$html  = '<tr id="newType_'.$one.'"><td align="right" style="width:120px"><font color="red">*</font>'.$newTypeInfo['title'].'：</td><td>';
					foreach($typePart as $tkey => $tone){
						$html .= '<label class="sinwlLabel"><input type="radio" value="'.$one.'_'.$tone.'"/>'.$tone.'</label>';
					}
					$html .= '</td></tr>';
				}elseif($type == 'checkbox'){
					$html  = '<tr id="newType_'.$one.'"><td align="right" style="width:120px"><font color="red">*</font>'.$newTypeInfo['title'].'：</td><td>';
					foreach($typePart as $tkey => $tone){
						$html .= '<label class="sinwlLabel"><input type="checkbox" value="'.$one.'_'.$tone.'"/>'.$tone.'</label>';
					}
					$html .= '</td></tr>';
				}
				$htmls[] = $html;
			}*/
		}
		if($xiangmu['newTypes']){
			$new_types = unserialize($xiangmu['newTypes']);
			sort($new_types);
			$count = count($new_types);
		}else{
			$count = 0;
		}
		if($xiangmu['color']){
			$colors = unserialize($xiangmu['color']);
			sort($colors);
			$count_color = count($colors);
		}else{
			$count_color = 0;
		}
		$uniqid = uniqid();
		$xiangmu['kucun'] = $xiangmu['maxqishu'] - $xiangmu['qishu'];
		include templates("mobile/index","goods");
	}
//临时  标签二页暂时写在这里  附加选项
	public function goods1(){
	$webname=$this->_yys['web_name'];
	$biaoti="商品选项";
	$index="i1";
	include templates("mobile/index","goods1");
	}
	//评论
	public function goods2(){
	$webname=$this->_yys['web_name'];
	$biaoti="商品评论";
	$index="i1";
	include templates("mobile/index","goods2");
	}
	//往期商品查看
	public function dataserver(){

		$id = intval($this->segment(4));
		$shopInfo = $this->db->Yone("select * from `@#_shangpin` where `id` = '$id'");
		$picarr = unserialize($shopInfo['picarr']);
		if($shopInfo['supplierId']){
			$supplierName = getSupplierInfo($shopInfo['supplierId'],'name');
		}
		
		$shopList = $this->db->YList("select * from `@#_shangpin` where `sid` = '$shopInfo[sid]' order by id DESC");
		$nowShop = $shopList['0'];
		$q_user = unserialize($shopInfo['q_user']);
		$ip = _huode_ip_dizhi();
		
		$xiangmuid=intval($this->segment(4));
		$xiangmu=$this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null LIMIT 1");
		if(!$xiangmu){
			_notemobile("商品不存在！");
		}

		if($xiangmu['q_showtime'] == 'Y'){
			header("location: ".LOCAL_PATH."/mobile/mobile/item/".$xiangmu['id']);
			exit;		
		}
		
		
		$xiangmulist = $this->db->Ylist("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' order by `qishu` DESC");
		$fenlei=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$xiangmu[cateid]' LIMIT 1");
		$pinpai=$this->db->YOne("select * from `@#_pinpai` where `id` = '$xiangmu[brandid]' LIMIT 1");
		
		//中奖码
		$q_yonghu = unserialize($xiangmu['q_user']);		
		$q_yonghu_code_len = strlen($xiangmu['q_user_code']);
		$q_yonghu_code_arr = array();
		for($q_i=0;$q_i < $q_yonghu_code_len;$q_i++){	
			$q_yonghu_code_arr[$q_i] = substr($xiangmu['q_user_code'],$q_i,1);
		}

		//期数显示
		$wangqiqishu='';
		if(empty($xiangmulist[0]['q_end_time'])){	
			$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/item/'.$xiangmulist[0]['id'].'">'."第".$xiangmulist[0]['qishu']."期</a><b></b></li>";
			array_shift($xiangmulist);
		}
			
		foreach($xiangmulist as $qitem){
			if($qitem['id'] == $xiangmuid){
				
				$wangqiqishu.='<li><a class="hover" href="javascript:;"><s class="fl"></s>'."第".$qitem['qishu']."期</a><b></b></li>";
			}else{				
				$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/dataserver/'.$qitem['id'].'" ><s class="fl"></s>第'.$qitem['qishu'].'期</a></li>';		
			}
		}
		 
		//总汇格同城次数
		$weer_shop_number = 0;
		//用户汇格同城时间
		$weer_shop_time = 0;
		//得到汇格同城码
		$weer_shop_codes = '';
		 
		$weer_shop_list = $this->db->Ylist("select * from `@#_yonghu_yys_record` where `uid`= '$xiangmu[q_uid]' and `shopid` = '$xiangmuid' and `shopqishu` = '$xiangmu[qishu]'");
		foreach($weer_shop_list as $weer_shop_n){
			$weer_shop_number += $weer_shop_n['gonumber'];
			if($weer_shop_n['huode']){
				$weer_shop_time = $weer_shop_n['time'];
				$weer_shop_codes = $weer_shop_n['goucode'];
			}
		}
		
		$h=abs(date("H",$xiangmu['q_end_time']));
		$i=date("i",$xiangmu['q_end_time']);
		$s=date("s",$xiangmu['q_end_time']);		
		$w=substr($xiangmu['q_end_time'],11,3);	
		$weer_shop_time_add = $h.$i.$s.$w;
		$weer_shop_fmod = fmod(($weer_shop_time_add*100+$xiangmu['cqsscnum']),$xiangmu['canyurenshu']);
		
		if($xiangmu['q_content']){
			$xiangmu['q_content'] = unserialize($xiangmu['q_content']);
		}
		$xiangmu['picarr'] = unserialize($xiangmu['picarr']) ;
		
		$jilus = $this->db->YList("select * from `@#_yonghu_yys_record` where `shopid` = '$xiangmu[id]' and `shopqishu` = '$xiangmu[qishu]' order by id desc");
		
		//记录	 
		$biaoti="已揭晓：".$xiangmu['title'];
		
//期数显示 PADDY修复期数不显示
		$xiangmuzx=$this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");
		//var_dump($xiangmuzx['qishu']);
		
	    $gorecode=$this->db->YOne("select *,sum(gonumber) as gonumber from `@#_yonghu_yys_record` where `shopid`='".$xiangmuid."' AND `shopqishu`='".$xiangmu['qishu']."' and `uid`= '$xiangmu[q_uid]'ORDER BY id DESC");

		$shopitem='dataserverfun';
		$curtime=time();
		
		//晒单数
		$shopid=$this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid'");
		$yyslist=$this->db->Ylist("select * from `@#_shangpin` where `sid`='$shopid[sid]'");
		$shop='';
		foreach($yyslist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidingdan=$this->db->Ylist("select * from `@#_shai` where `sd_shopid` IN ($id)");
			$sum=0;
			foreach($shaidingdan as $sd){
				$shaidingdan_hueifu=$this->db->Ylist("select * from `@#_shai_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidingdan_hueifu);
			}
		}else{
			$shaidingdan=0;
			$sum=0;
		}
		$xiangmuxq=0;
		if(!empty($xiangmuzx)){
		  $xiangmuxq=1;
		}
		 
		 /*插入记录*/
		 	  $xiangmuid=intval($this->segment(4));
	  	$xiangmu=$this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null LIMIT 1");
	  

	  $xiangmuzx=$this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");

	    $h=abs(date("H",$xiangmu['q_end_time']));
		$i=date("i",$xiangmu['q_end_time']);
		$s=date("s",$xiangmu['q_end_time']);		
		$w=substr($xiangmu['q_end_time'],11,3);	
		$weer_shop_time_add = $h.$i.$s.$w;

		$weer_shop_fmod = fmod($xiangmu['q_counttime']+$xiangmu['cqsscnum'],$xiangmu['canyurenshu']);

		//var_dump($weer_shop_fmod);
		//$weer_shop_fmod = fmod($xiangmu['q_counttime'],$xiangmu['canyurenshu']);
		
		if($xiangmu['q_content']){
			$xiangmu['q_content'] = unserialize($xiangmu['q_content']);
		}
        $xiangmu['picarr'] = unserialize($xiangmu['picarr']) ;
		 
		include templates("mobile/index","dataserver");
	}
	
	
	//more

	public function more(){
		$qishu = $_REQUEST['qishu'];
		if($qishu){
			//print_r($qishu);
			$shangpin = $this->db->YOne("select * from `@#_shangpin` where `qishu` = '".intval($qishu)."' order by `id` desc");
			header("Location:/mobile/mobile/item/".$shangpin['id']);
		}
		//exit;
	    $webname=$this->_yys['web_name'];
		$key="揭晓结果";
		$xiangmuid = intval($this->segment(4));
		$xiangmu = $this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null LIMIT 1");
		
		
		
		$xiangmulist = $this->db->Ylist("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' order by `qishu` DESC");
		$fenlei=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$xiangmu[cateid]' LIMIT 1");
		$pinpai=$this->db->YOne("select * from `@#_pinpai` where `id` = '$xiangmu[brandid]' LIMIT 1");
		
		//汇格同城中奖码
		$q_yonghu = unserialize($xiangmu['q_user']);		
		$q_yonghu_code_len = strlen($xiangmu['q_user_code']);
		$q_yonghu_code_arr = array();
		for($q_i=0;$q_i < $q_yonghu_code_len;$q_i++){	
			$q_yonghu_code_arr[$q_i] = substr($xiangmu['q_user_code'],$q_i,1);
		}

		//期数显示
		$wangqiqishu='';
		if(empty($xiangmulist[0]['q_end_time'])){	
			$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/item/'.$xiangmulist[0]['id'].'">'."第".$xiangmulist[0]['qishu']."期</a><b></b></li>";
			array_shift($xiangmulist);
		}
			
		foreach($xiangmulist as $qitem){
			if($qitem['id'] == $xiangmuid){
				
				$wangqiqishu.='<li><a class="hover" href="javascript:;"><s class="fl"></s>'."第".$qitem['qishu']."期</a><b></b></li>";
			}else{				
				$wangqiqishu.='<li><a href="'.LOCAL_PATH.'/mobile/mobile/dataserver/'.$qitem['id'].'" ><s class="fl"></s>第'.$qitem['qishu'].'期</a></li>';		
			}
		}
		 
		//总汇格同城次数
		$weer_shop_number = 0;
		//用户汇格同城时间
		$weer_shop_time = 0;
		//得到汇格同城码
		$weer_shop_codes = '';
		 
		$weer_shop_list = $this->db->Ylist("select * from `@#_yonghu_yys_record` where `uid`= '$xiangmu[q_uid]' and `shopid` = '$xiangmuid' and `shopqishu` = '$xiangmu[qishu]'");
		foreach($weer_shop_list as $weer_shop_n){
			$weer_shop_number += $weer_shop_n['gonumber'];
			if($weer_shop_n['huode']){
				$weer_shop_time = $weer_shop_n['time'];
				$weer_shop_codes = $weer_shop_n['goucode'];
			}
		}
		
		$h=abs(date("H",$xiangmu['q_end_time']));
		$i=date("i",$xiangmu['q_end_time']);
		$s=date("s",$xiangmu['q_end_time']);		
		$w=substr($xiangmu['q_end_time'],11,3);	
		$weer_shop_time_add = $h.$i.$s.$w;
		$weer_shop_fmod = fmod($weer_shop_time_add*100,$xiangmu['canyurenshu']);
		
		if($xiangmu['q_content']){
			$xiangmu['q_content'] = unserialize($xiangmu['q_content']);
		}
        $xiangmu['picarr'] = unserialize($xiangmu['picarr']) ;
		
		//记录	 
		
		
	    $gorecode=$this->db->YOne("select * from `@#_yonghu_yys_record` where `shopid`='".$xiangmuid."' AND `shopqishu`='".$xiangmu['qishu']."' and `uid`= '$xiangmu[q_uid]'ORDER BY id DESC LIMIT 6");
        
		$shopitem='dataserverfun';
		$curtime=time();
		//晒单数
		$shopid=$this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid'");
		$yyslist=$this->db->Ylist("select * from `@#_shangpin` where `sid`='$shopid[sid]'");
		$shop='';
		foreach($yyslist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidingdan=$this->db->Ylist("select * from `@#_shai` where `sd_shopid` IN ($id)");
			$sum=0;
			foreach($shaidingdan as $sd){
				$shaidingdan_hueifu=$this->db->Ylist("select * from `@#_shai_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidingdan_hueifu);
			}
		}else{
			$shaidingdan=0;
			$sum=0;
		}
		$xiangmuxq=0;
		if(!empty($xiangmuzx)){
		  $xiangmuxq=1;
		}
		 
		include templates("mobile/index","more");
	}
	
	//************************************************//
	//************************************************//
	//************************************************//
	
	public function tenpaysuccess(){
	    $webname=$this->_yys['web_name'];
		$code= _getcookie('CODE');
		if(!isset($_GET['attach'])){
			_notemobile("资源不存在!");
			exit;
		}
		if(!$code){
			_notemobile("资源不存在!");
			exit;
		}
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$zongji_fee      = $_GET['total_fee']/100+$huiyuan['money'];
		$attach         = $_GET['attach'];
		$sign           = $_GET['sign'];
		if($pay_result<1){			
			$mysql_model->Query("UPDATE `@#_yonghu` SET money='".$zongji_fee."' where uid='".$huiyuan['uid']."'");			
			$shop=explode("&",$attach);
			gopay($huiyuan,$shop[0],$shop[1],$shop[2]);
		}
	}	

	//最新揭晓
	public function lottery(){	
	    $webname=$this->_yys['web_name'];
		$yysqishu=$this->db->Ylist("select * from `@#_shangpin` where `q_end_time` is not null ORDER BY `q_end_time` DESC LIMIT 0,4");	
		$yyslist=$this->db->Ylist("select * from `@#_shangpin` where 1 ORDER BY `canyurenshu` DESC LIMIT 4");
		$huiyuan_record=$this->db->Ylist("select * from `@#_yonghu_yys_record` order by id DESC limit 6");
		$biaoti = "最新揭晓";
		include templates("mobile/index","lottery");
	}
	
	//商品购买记录
	public function buyrecords(){	
	    $webname=$this->_yys['web_name'];
		$key="所有汇格同城记录";
		$xiangmuid=intval($this->segment(4));
		$cords=$this->db->Ylist("select * from `@#_yonghu_yys_record` where `shopid`='$xiangmuid' order by time desc");
		
		include templates("mobile/index","buyrecords");
	}
	//图文详细
	public function goodsdesc(){
	    $webname=$this->_yys['web_name'];
		$key="图文详情";
		$xiangmuid=intval($this->segment(4));
		$desc=$this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid'");
		if(!$desc){
			_notemobile('该商品已经不存在，请联系客服!');
		}
		include templates("mobile/index","goodsdesc");
	}
	//直购商品图文详细
	public function goodsdesczg(){
	    $webname=$this->_yys['web_name'];
		$key="直购商品图文详情";
		$xiangmuid=intval($this->segment(4));
		$desc=$this->db->YOne("select * from `@#_zg_shangpin` where `id`='$xiangmuid'");
		if(!$desc){
			_notemobile('该商品已经不存在，请联系客服!');
		}
		include templates("mobile/index","goodsdesczg");
	}
	//晒单评论
	public function goodspost(){
	    $webname=$this->_yys['web_name'];
		$key="晒单评论";
		$xiangmuid=intval($this->segment(4));
		$yyslist=$this->db->Ylist("select * from `@#_shangpin` where `sid`='$xiangmuid'");
		if(!$yyslist){
			_notemobile('资源不存在!');
		}
		$shop='';
		foreach($yyslist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidingdan=$this->db->Ylist("select * from `@#_shai` where `sd_shopid` IN ($id) order by `sd_id` DESC");
			$sum=0;
			foreach($shaidingdan as $sd){
				$shaidingdan_hueifu=$this->db->Ylist("select * from `@#_shai_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidingdan_hueifu);
			}
		}else{
			$shaidingdan=0;
			$sum=0;
		}
		include templates("mobile/index","goodspost");
	}
	
	public function calResult(){
	  $xiangmuid=intval($this->segment(4));
	  	$xiangmu=$this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null LIMIT 1");
	  

	  $xiangmuzx=$this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");



	    $h=abs(date("H",$xiangmu['q_end_time']));
		$i=date("i",$xiangmu['q_end_time']);
		$s=date("s",$xiangmu['q_end_time']);		
		$w=substr($xiangmu['q_end_time'],11,3);	
		$weer_shop_time_add = $h.$i.$s.$w;

		$weer_shop_fmod = fmod($xiangmu['q_counttime']+$xiangmu['cqsscnum'],$xiangmu['canyurenshu']);

		//var_dump($weer_shop_fmod);
		//$weer_shop_fmod = fmod($xiangmu['q_counttime'],$xiangmu['canyurenshu']);
		
		if($xiangmu['q_content']){
			$xiangmu['q_content'] = unserialize($xiangmu['q_content']);
		}
        $xiangmu['picarr'] = unserialize($xiangmu['picarr']) ;
	  
	  include templates("mobile/index","calResult");
	}
	//新手指南
	public function about(){
	 $webname=$this->_yys['web_name'];
	 $fenlei=$this->db->YOne("select * from `@#_fenlei` where `parentid`='1' and `name`='新手指南'");
	 
	 $wenzhang=$this->db->Ylist("select * from `@#_wenzhang` where `cateid`='$fenlei[cateid]'");
	 
	include templates("mobile/index","about");
	}	

	//用户服务协议
	public function terms(){
	$biaoti="服务协议_"._yys("web_name");
	$webname=$this->_yys['web_name'];
	 $fenlei=$this->db->YOne("select * from `@#_fenlei` where `parentid`='1' and `name`='新手指南'");
	 
	 $wenzhang=$this->db->YOne("select * from `@#_wenzhang` where `id`='3' ");
	 $wenzhang['posttime'] = date('Y-m-d H:i:s',$wenzhang['posttime']);
	 $hit = $wenzhang['hit'] + 1;
	updateSet(array('hit'=>$hit),'wenzhang',3);
	//echo "<pre>";
	//print_r($wenzhang);
	  include templates("mobile/system","terms");
	}	
	
	//访问个人主页
	public function userindex(){

	  $uid=safe_replace($this->segment(4));
	  //$uid=intval($this->segment(4))-1000000000;
	  //获取个人资料
	  $huiyuan=$this->db->YOne("select * from `@#_yonghu` where `uid`='$uid'");
	  
	  //获取等级设置
	  $huiyuandj=$this->db->Ylist("select * from `@#_yonghu_group`");
	  $jingyan=$huiyuan['jingyan'];
	  if(!empty($huiyuandj)){
	     foreach($huiyuandj as $key=>$val){
		    if($jingyan>=$val['jingyan_start'] && $jingyan<=$val['jingyan_end']){
			   $huiyuan['yungoudj']=$val['name'];
			   $huiyuan['icon']=$val['icon'];
			}			
		 }
	  }  
	  $biaoti=$huiyuan['username']."个人主页";
	  include templates("mobile/index","userindex");
	}
 
	/*
	//今日揭晓
	public function autolottery(){
	    $w_jinri_time = strtotime(date('Y-m-d'));
		$w_minri_time = strtotime(date('Y-m-d',strtotime("+1 day")));
		
		$jinri_shoplist = $this->db->Ylist("select * from `@#_shangpin` where `xsjx_time` > '$w_jinri_time' and `xsjx_time` < '$w_minri_time' order by xsjx_time limit 0,3 ");
		include templates("mobile/index","buyrecords");
	
	}
    
	//明日揭晓
	public function nextautolottery(){		 
		$w_minri_time = strtotime(date('Y-m-d',strtotime("+1 day")));
		$w_houri_time = strtotime(date('Y-m-d',strtotime("+2 day")));
		
		$jinri_shoplist = $this->db->Ylist("select * from `@#_shangpin` where `xsjx_time` > '$w_minri_time' and `xsjx_time` < '$w_houri_time' order by xsjx_time limit 0,3 ");
	}*/

	function callbackWechat()
	{
			
	    $procode = $this->segment(4);
	    echo "<pre>";
		print_r($_REQUEST);
		die();
		
		$wx_openid = $_REQUEST["unionid"];
		
	    if (empty($wx_openid)) {
	        _note("绑定出错，请联系管理员。");
	        die();
	    }
	    
	    $nickname = $_REQUEST["nickname"];
	    $go_user_info = $this->db->YOne("select * from `@#_yonghu_band` where `b_code` = '$wx_openid' and `b_type` = 'weixin' LIMIT 1");
$ip = _huode_ip_dizhi();
		$time = time();

	    if (!$go_user_info) {
	       // $wxImg = file_get_contents($_GET["headimgurl"]);
	        $timeStamp = time();
	        //$localImg = $_SERVER['DOCUMENT_ROOT'] . '/statics/uploads/photo/' . $timeStamp . '.jpg';
	        //file_put_contents($localImg, $wxImg);
	        $userpass = md5("123456");
	        $go_user_img = 'photo/member.jpg';
	        $go_user_time = time();
	        $this->db->Query("INSERT INTO `@#_yonghu` (`username`,`password`,`img`,`band`,`time`,`money`,`first`,`code`,`user_ip`,`login_time`) VALUES ('$nickname','$userpass','$go_user_img','weixin','$go_user_time',0,1,'$procode','$ip','$time')");
	
	        $uid = $this->db->last_id();
	
	        $this->db->Query("INSERT INTO `@#_yonghu_band` (`b_uid`, `b_type`, `b_code`, `b_time`) VALUES ('$uid', 'weixin', '$wx_openid', '$go_user_time')");
	        $member = $this->db->YOne("select uid,password,mobile,email from `@#_yonghu` where `uid` = '$uid' LIMIT 1");
	
	        _setcookie("uid", _encrypt($member['uid']), 60 * 60 * 24 * 7);
	        _setcookie("ushell", _encrypt(md5($member['uid'] . $member['password'] . $member['mobile'] . $member['email'])), 60 * 60 * 24 * 7);

 	        $callback_url = LOCAL_PATH . "/mobile/home/";
 	        header("Location:$callback_url");
	    } else {

	        $uid = $go_user_info["b_uid"];
		$this->db->Query("UPDATE `@#_yonghu` SET user_ip='$ip',`login_time`='$time' where uid='$uid'");
	        $member = $this->db->YOne("select uid,password,mobile,email from `@#_yonghu` where `uid` = '$uid' LIMIT 1");
	   
	        _setcookie("uid", _encrypt($member['uid']), 60 * 60 * 24 * 7);
	        _setcookie("ushell", _encrypt(md5($member['uid'] . $member['password'] . $member['mobile'] . $member['email'])), 60 * 60 * 24 * 7);
			
  	        $callback_url = LOCAL_PATH . "/mobile/home/";
   	        header("Location:$callback_url");
	    }
	}



	public function chongzhi(){

			include templates("mobile/index","chongzhi");
	}
	
	//新增一个获取最新开奖
	public function getNew(){
		//最新揭晓
		$yysqishu = $this->db->Ylist("select * from `@#_shangpin` where `q_end_time` is not null ORDER BY `q_end_time` DESC LIMIT 2");
		
		foreach($yysqishu as $key => $one){
			//查看是否已过期
			$diffTime = microtime(true) - $one['q_end_time'];
			
			$sinwl[$key]['id']				= $one['id'];
			$sinwl[$key]['title']			= $one['title'];
			
			if($diffTime > 0){
				$sinwl[$key]['status'] = '1';
			}else{
				$sinwl[$key]['status'] = '0';
			}
			$sinwl[$key]['thumb']			= $one['thumb'];
			$sinwl[$key]['data_end'] 		= date('Y/m/d H:i:s',$one['q_end_time']); 
			$sinwl[$key]['q_uid']			= $one['q_uid'];
			$sinwl[$key]['huode_user_name'] = huode_user_name($one['q_uid']);
		}
		
		//echo "<pre>";
		//print_r($sinwl);

		echo json_encode($sinwl);
	}
	
	
	//处理抢钱
	public function getmoneygames(){
		
		$interval = 30;
		$uid = $this->userinfo['uid'];
		
		if(!$uid){
			_notemobile("请登录",LOCAL_PATH."/mobile/user/login",3);
	        die();
		}
		
		$gameRecord = $this->db->YList("select * from `@#_game_record` where `uid` = '$uid' order by `createTime` desc limit 1");

		$diffTime = (time() - $gameRecord['0']['createTime']) / 60;
		
		
		if($gameRecord && $diffTime < $interval){
			$nextTime = intval($interval - $diffTime);
			$result = array(
				'status' => 0,
				'info' => '还差'.$nextTime."分钟可以再玩一次！",
			);
		}else{
			$result = array(
				'status' => 1,
			);
		}
		
		$signPackage = $this->GetSignPackage();

		$appId 		= $signPackage["appId"];
		$timestamp 	= $signPackage["timestamp"];
		$nonceStr	= $signPackage["nonceStr"];
		$signature	= $signPackage["signature"];
		
		
		$gameConfig = System::DOWN_App_config("game_config");
		
		
		
		include templates("mobile/index","getmoneygames");
	}
	
	public function ajaxCan(){
		$gameConfig = System::DOWN_App_config("game_config");
		$interval = $gameConfig['diffTime'];
		$uid = $this->userinfo['uid'];
		$gameRecord = $this->db->YList("select * from `@#_game_record` where `uid` = '$uid' order by `createTime` desc limit 1");
		$diffTime = (time() - $gameRecord['0']['createTime']) / 60;
		if($gameRecord && $diffTime < $interval){
			$result = array(
				'info' => 0,
			);
		}else{
			$result = array(
				'info' => 1,
			);
		}
		echo json_encode($result);
	}
	
	public function addPrize(){
		$uid = $this->userinfo['uid'];
		$money = intval(intval($_REQUEST['num1']).intval($_REQUEST['num2']));
		$time = time();
		$user = $this->db->YOne("select * from `@#_yonghu` where `uid` = '$uid'");

		if($user){
			$gameConfig = System::DOWN_App_config("game_config");
			$interval = $gameConfig['diffTime'];
			
			$gameRecord = $this->db->YList("select * from `@#_game_record` where `uid` = '$uid' order by `createTime` desc limit 1");
			$diffTime = (time() - $gameRecord['createTime']) / 60;
			if(!$gameRecord || $diffTime > $interval){
				$sql  = "INSERT INTO `@#_game_record` (`uid`,`money`,`createTime`)";
				$sql .= " VALUES ('$uid','$money','$time')";
				$res = $this->db->Query($sql);
				
				if($res){			
					$fufen = $money;
					$time = time();
					$sql  = "INSERT INTO `@#_yonghu_zhanghao` (`uid`,`type`,`pay`,`content`,`money`,`time`)";
					$sql .= " VALUES ('$uid','1','福分','游戏获得','$money','$time')";
					$res = $this->db->Query($sql);
					if($res){
						$sql = "UPDATE `@#_yonghu` SET `score` = `score` + $fufen WHERE `uid` = '$uid'";
						$res = $this->db->Query($sql);
						if($res){
							$result = array(
								'status' => 1,
								'info' => "恭喜本次参与游戏，（".$money."福分）已同步到您的账户。",
							);
						}else{
							$result = array(
								'status' => 0,
								'info' => "游戏成功，插入记录失败，请保留本页截图联系管理员！",
							);
						}
					}else{
						$result = array(
							'status' => 0,
							'info' => "游戏成功，插入记录失败，请保留本页截图联系管理员！",
						);
					}		
				}else{
					$nextTime = intval($interval - $diffTime);
					$result = array(
						'status' => 0,
						'info' => '还差'.$nextTime."分钟可以再玩一次！",
					);
				}
			}else{
				$result = array(
					'status' => 0,
					'info' => $interval."分钟之内只能玩一次哦！",
				);
			}
		}else{
			$result = array(
				'status' => 0,
				'info' => '未登录或账号不正常，请稍候再试',
			);
		}
		
		echo json_encode($result);
	}
	
	public function getSignPackage() {
		$jsapiTicket = $this->getJsApiTicket();
		$url = LOCAL_PATH."/mobile/mobile/getmoneygames";
		
		// 注意 URL 一定要动态获取，不能 hardcode.
		$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
		$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

		
		$timestamp = time();
		$nonceStr = $this->createNonceStr();

		// 这里参数的顺序要按照 key 值 ASCII 码升序排序
		$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
		
		$signature = sha1($string);

		$signPackage = array(
			"appId" => $this->appId,
			"nonceStr" => $nonceStr,
			"timestamp" => $timestamp,
			"url" => $url,
			"signature" => $signature,
			"rawString" => $string
		);
		
		return $signPackage; 
	}
	
	public function createNonceStr($length = 16) {
		$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		$str = "";
		for ($i = 0; $i < $length; $i++) {
			$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
		}
		return $str;
	}
	
	public function getJsApiTicket() {
		// jsapi_ticket 应该全局存储与更新，以下代码以写入到文件中做示例
		$data = json_decode(file_get_contents("jsapi_ticket.json"));
		
		
		if ($data->expire_time < time()){
			$accessToken = $this->getAccessToken();
			$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
			$res = json_decode(file_get_contents($url));
			$ticket = $res->ticket;

			if ($ticket) {
				$data->expire_time = time() + 7000;
				$data->jsapi_ticket = $ticket;
				$fp = fopen("jsapi_ticket.json", "w");
				fwrite($fp, json_encode($data));
				fclose($fp);
			}
		} else {
			$ticket = $data->jsapi_ticket;
		}
		return $ticket;
	}
	
	public function getAccessToken() {
		// access_token 应该全局存储与更新，以下代码以写入到文件中做示例
		$data = json_decode(file_get_contents("access_token.json"));
		if ($data->expire_time < time()) {
		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
		
		$res = json_decode(file_get_contents($url));

		$access_token = $res->access_token;
		if ($access_token) {
			$data->expire_time = time() + 7000;
			$data->access_token = $access_token;
			$fp = fopen("access_token.json", "w");
				fwrite($fp, json_encode($data));
				fclose($fp);
			}
		} else {
			$access_token = $data->access_token;
		}
		return $access_token;
	}

	public function httpGet($url) {
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_TIMEOUT, 500);
		curl_setopt($curl, CURLOPT_URL, $url);

		$res = curl_exec($curl);
		curl_close($curl);

		return $res;
	}

	public function coupon(){
		$webname=$this->_yys['web_name'];	
		$biaoti = "代金券列表_"._yys("web_name");
		$key = "代金券";
		include templates("mobile/index","coupon");
	}
	
	public function couponinfo(){
		
		$webname=$this->_yys['web_name'];
		$key="代金券详情";
		$mysql_model=System::DOWN_sys_class('model');
		$xiangmuid=safe_replace($this->segment(4));	
		
		$xiangmu=$mysql_model->YOne("select * from `@#_coupon` where `id`='".$xiangmuid."' LIMIT 1");

		if(!$xiangmu)_notemobile("商品不存在！");
		$q_showtime = (isset($xiangmu['q_showtime']) && $xiangmu['q_showtime'] == 'N') ? 'N' : 'Y';
		if($xiangmu['q_end_time'] && $q_showtime == 'N'){
			header("location: ".LOCAL_PATH."/mobile/mobile/dataserver/".$xiangmu['id']);
			exit;			
		}
		$sid=$xiangmu['sid'];
		$sid_code=$mysql_model->YOne("select * from `@#_shangpin` where `sid`='$sid' order by `id` DESC LIMIT 1,1");
		$sid_go_record=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `shopid`='$sid_code[sid]' and `uid`='$sid_code[q_uid]' order by `id` DESC LIMIT 1");
		
		
		$fenlei=$mysql_model->YOne("select * from `@#_fenlei` where `cateid` = '$xiangmu[cateid]' LIMIT 1");
		$pinpai=$mysql_model->YOne("select * from `@#_pinpai` where `id`='$xiangmu[brandid]' LIMIT 1");
		
		$biaoti=$xiangmu['title'];
		$nomal = $xiangmu['zongrenshu']-$xiangmu['canyurenshu'];
		$xiangmu['picarr'][] = $xiangmu['thumb'];


		include templates("mobile/index","couponinfo");
	}
	//分类
	public function category(){
		$biaoti="产品分类";
		$index="i1";
		$categoryList = $this->db->YList("select * from `@#_fenlei` where `parentid` = '0' and `model` = '1' order by `order` desc");
		
		foreach($categoryList as $key => $one){
			$categoryList[$key]['sub'] = $this->db->YList("select * from `@#_fenlei` where `parentid` = '$one[cateid]' and `model` = '1' order by `order` desc");
		}
		include templates("mobile/index","category");
	}
	//行业@#_supplier_type
	public function industry(){
		$biaoti="行业分类";
		$index="i2";
		$categoryList = $this->db->YList("select * from `@#_fenlei` where `parentid` = '0' and `model` = '3' order by `order` desc");
		
		foreach($categoryList as $key => $one){
			$categoryList[$key]['sub'] = $this->db->YList("select * from `@#_fenlei` where `parentid` = '$one[cateid]' and `model` = '3' order by `order` desc");
		}
		include templates("mobile/index","industry");
	}
	
		/*帮助反馈*/
	public function help(){
		$biaoti="帮助反馈";
		$wenzhang = $this->db->Ylist("select * from `@#_wenzhang` where `cateid` = '89' order by `order` desc");
		include templates("mobile/help","help");
	}
	
	/*帮助反馈详情*/
	public function helpDetail(){
		$id = $this->segment(4);
		$wenzhang = $this->db->Yone("select * from `@#_wenzhang` where `id` = '$id'");
		$wenzhang['posttime'] = date('Y-m-d H:i:s',$wenzhang['posttime']);
		$hit = $wenzhang['hit'] + 1;
		updateSet(array('hit'=>$hit),'wenzhang',$id);
		$biaoti=$wenzhang['title'];

		//调用分享部分开始
		$deng=$this->userinfo;
		if($_GET['yaoqing']){
			$uu=$_GET['yaoqing'];
			session_start();
			$_SESSION['uu']=$uu;
		}

		if($_GET['yaoqing2']){
			$yaoqing2=$_GET['yaoqing2'];
			session_start();
			$_SESSION['yaoqing2']=$yaoqing2;
		}

		if($_GET['yaoqing3']){
			$yaoqing3=$_GET['yaoqing3'];
			session_start();
			$_SESSION['yaoqing3']=$yaoqing3;
		}
		//var_dump($_SESSION['yaoqing2']);
		require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
      
	   $appid = $yaoqing[appid];
	   $secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		//exit;		
		/*调用分享结束*/
		include templates("mobile/help","helpDetail");
	}	
	/*公告情*/
	public function noticeDetail(){
		$id = $this->segment(4);
		$wenzhang = $this->db->Yone("select * from `@#_notice` where `id` = '$id'");
		$wenzhang['create_time'] = date('Y-m-d H:i:s',$wenzhang['create_time']);

		$this->db->Query("update `@#_notice` set `hit` = `hit` + 1 where `id` = '$id'");
		$biaoti=$wenzhang['title'];

		//调用分享部分开始
		$deng=$this->userinfo;
		if($_GET['yaoqing']){
			$uu=$_GET['yaoqing'];
			session_start();
			$_SESSION['uu']=$uu;
		}

		if($_GET['yaoqing2']){
			$yaoqing2=$_GET['yaoqing2'];
			session_start();
			$_SESSION['yaoqing2']=$yaoqing2;
		}

		if($_GET['yaoqing3']){
			$yaoqing3=$_GET['yaoqing3'];
			session_start();
			$_SESSION['yaoqing3']=$yaoqing3;
		}
		//var_dump($_SESSION['yaoqing2']);
		require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
      
	   $appid = $yaoqing[appid];
	   $secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		//exit;		
		/*调用分享结束*/
		include templates("mobile/index","noticeDetail");
	}		
	
	
		/*测试*/
	public function test(){
		$biaoti="测试";
		$huiyuan = $this->userinfo;
		$provinceList = $this->db->Ylist("select * from `@#_area` where `parentId` = '0'");
		$goto = htmlspecialchars($_GET['goto']);
		
		
		
		
		include templates("mobile/index","test");
	}
/*
沉积备用系统模块
*/
	//首页
	public function yun(){

		//邀请关系
        session_start();
		if(isset($_GET['yaoqing']) && $_GET['yaoqing'] != null){
			$_SESSION['uu'] = $_GET['yaoqing'];
		}
        if(isset($_GET['fid']) && $_GET['fid'] != null){
            $_SESSION['fid'] = $_GET['fid'];
            $_SESSION['uu'] = $_GET['fid'];
        }

		$webname=$this->_yys['web_name'];
		$biaoti=""._yys("web_name");
		$index="i0";
		//最新商品
		$new_shop=$this->db->YOne("select * from `@#_zg_shangpin` where `pos` = '1' and `q_end_time` is null ORDER BY `id` DESC LIMIT 1");

		//即将揭晓
		$yyslist = $this->db->Ylist("select * from `@#_zg_shangpin` where `q_end_time` is null ORDER BY `shenyurenshu` ASC LIMIT 8");

		//人气商品
		$yyslistrenqi=$this->db->Ylist("select * from `@#_zg_shangpin` where `renqi`='1' and `q_end_time` is null ORDER BY id DESC LIMIT 12");
		
		//直购人气商品
		$yyslistrenqizg=$this->db->Ylist("select * from `@#_zg_shangpin` where `renqi`='1' and `q_end_time` is null ORDER BY id DESC LIMIT 8");

		//最新揭晓
		$yysqishu=$this->db->Ylist("select * from `@#_zg_shangpin` where `q_end_time` is not null and `q_showtime` = 'N' ORDER BY `q_end_time` DESC LIMIT 4");
		
		$jinri_shoplist = $this->db->Ylist("select * from `@#_zg_shangpin` where `xsjx_time` > '$w_jinri_time' and `xsjx_time` < '$w_minri_time' order by xsjx_time limit 0,3 ");

		$shouji_tu = $this->db->YList("select * from `@#_shouji` order by id desc limit 4");
		/*require_once("yungousys/class/mobile/jssdk.php");
		$yaoqing = System::DOWN_App_config("user_fufen");
	
		$appid = $yaoqing[appid];
		$secret = $yaoqing[secret];
		$jssdk = new JSSDK($appid, $secret);
		$signPackage = $jssdk->GetSignPackage();
		$biaoti = "首页";*/
	
		/*公告列表*/		      	


		/*
		*	导航图
		*	这里放大类
		*/
		$nav_list = $this->db->YList("select * from `@#_daohang` where `type` = 'mobile' and `status` = 'Y' order by `order` desc");
		foreach($nav_list as $key => $one){
			if($one['thumb']){
				$nav_list[$key]['thumb'] = $one['thumb'];
			}else{
				$nav_list[$key]['thumb'] = 'pp.gif';
			}
		}
		
		/*品牌图*/
		$brand_list = $this->db->YList("select * from `@#_fenlei` where `model` = '1' order by `order` desc,`cateid` desc limit 10");
	

		foreach($brand_list as $key => $one){
			$info = unserialize($one['info']);
			if($info['thumb']){
				$brand_list[$key]['thumb'] = $info['thumb'];
			}else{
				$brand_list[$key]['thumb'] = 'pp.gif';
			}
		}
		
		$brand_list_two = $this->db->YList("select * from `@#_fenlei` where `model` = '1' order by `order` desc,`cateid` desc");
	
		$action = 'index';
		
		/*如果没有正在开奖，则取最近开奖的四个*/
		$prizeList = $this->db->Ylist("select * from `@#_shangpin` where `canyurenshu` = `zongrenshu` and `shenyurenshu` = '0' and `q_showtime` = 'N' and `q_uid` IS NOT NULL order by `q_end_time` desc,`id` desc limit 4"); 
		if($prizeList){
			foreach($prizeList as $key => $one){
				$username = unserialize($one['q_user']);
				$prizeList[$key]['username'] = $username['username'];
			}
		}
		if( !$_GET['yaoqing'] && !$_GET['fid']) {
			include templates("mobile/index","yun");
		}else{
			header("location:/mobile/user/login");
		}
	}	
}
?>